//
//  HomeOwnViewModel.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/2/3.
//

import Foundation
import SwiftUI

//错误日志
class AiCustomErrorViewModel : BaseViewModel {
    
    @Published var items = [AiCustomErrorBean]()
    @Published var status = ""

    
    func getData(_ isRefresh: Bool = false,id : String) {
        requestList(isRefresh: isRefresh) {
            let dao = AiCustomErrorDao()
            let list = try await dao.getList(id: id, pageNo: self.pageNo, pageSize: self.pageSize)
            try check(!isRefresh || !list.isEmpty, "暂无错误日志")
            return list
        } suc: { list in
            self.status = ""
            if isRefresh {
                self.items = list
            } else {
                self.items.append(contentsOf: list)
            }
        } fail: {
            self.status = $0.message
        }
    }
    
    func doDel(list: [AiCustomErrorBean], suc: @escaping () -> Void) {
        request {
            let dao = AiCustomErrorDao()
            for bean in list {
               try await dao.doDel(bean: bean)
            }
            return true
        } suc: { _ in
            suc()
        } fail: {
            showToast($0.message)
        }
    }
    
}
